Generating nested dictionary from a text file